package com.heima.admin.controller.v1;

import com.heima.admin.service.ChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.dtos.ResponseResult;
import com.heima.model.admin.pojos.AdChannel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "频道管理API",value = "频道管理API")
@RestController
@RequestMapping("api/v1/channel")
public class AdChannelController {
@Autowired
    ChannelService channelService;

    @ApiOperation("根据名称模糊分页查询")
    @PostMapping("list")
    public ResponseResult list(@RequestBody ChannelDto dto) {
        return channelService.findByNameAndPage ( dto );
    }

    @ApiOperation(value = "添加频道",notes = "频道不能为空，不能重名")
    @PostMapping("save")
    public ResponseResult save(@RequestBody AdChannel channel) {
        return channelService.insert(channel);
    }


    @ApiOperation(value = "修改频道",notes = "修改/启用和禁用的共用方法")
    @PostMapping("update")
    public ResponseResult update(@RequestBody AdChannel channel) {
        return channelService.update(channel);
    }
    @ApiOperation("根据频道ID删除")
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return channelService.deleteById(id);
    }

}
